package com.hjqjl.whdemo.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.hjqjl.whdemo.R;

public class DialogTop extends Dialog {
    public static DialogTop show(Context context) {
        DialogTop dialogTop = new DialogTop(context);
        dialogTop.show();
        return dialogTop;
    }

    public DialogTop(@NonNull Context context) {
        super(context, R.style.DialogFullScreen);//设置全屏样式对话框边上的空白就会消失
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_top);
        Window window = getWindow();
        if (window != null) {
            WindowManager.LayoutParams windowParams = window.getAttributes();
            windowParams.dimAmount = 0.0f;//Dialog外边框透明
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); //高度自适应，宽度全屏
            windowParams.gravity = Gravity.TOP; //在顶部显示
            windowParams.windowAnimations = R.style.TopDialogAnimation;
            window.setAttributes(windowParams);
        }
    }
}
